<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	
	if (isset($_GET['id']))
	{
		$course_section_id = mysql_real_escape_string(strip_tags($_GET['id']));
	}
	else
	{
		header('Location:postSchedule.php');
		exit(0);
	}
	
	if (isset($_GET['building_id']))
	{
		$building_id = mysql_real_escape_string(strip_tags($_GET['building_id']));
	}
	if (isset($_GET['semester_id']))
	{
		$semester_id = mysql_real_escape_string(strip_tags($_GET['semester_id']));
	}
	
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');
?>
	<p><a href="postSchedule.php?building_id=<?php echo $building_id; ?>&amp;semester_id=<?php echo $semester_id; ?>">&lt;&lt; Back to Schedule</a></p>
	
	<h1>Collision Log</h1>

	<table class="postSchedule">
        <tr>
            <th>Days</th>
            <th>Time</th>
            <th>Classroom</th>
            <th>Description of Collision</th>
        </tr>
        <?php
		
		$query = "SELECT *, b.abbreviation AS b_abbrev
				  FROM collision_log cl
				  JOIN course_sections csec ON csec.id = cl.section_id
				  LEFT JOIN classrooms cr ON cr.id = cl.classroom_id
				  LEFT JOIN buildings b ON b.id = cr.building_id
				  LEFT JOIN time_slots ts ON ts.id = cl.timeslot_id
				  WHERE cl.section_id = '$course_section_id'
				  ORDER BY cl.id";
		
		$result = mysql_query($query);
		echo mysql_error();
		$row_count = 0;
		while($row = mysql_fetch_assoc($result))
		{
			$row_count++;
			?>
			<tr<?php if (($row_count%2) != 0) echo " class=\"zebra_stripe\""; ?>>
				<td><?php
					if (!empty($row['timeslot_id']))
					{
						$days_of_week = '';
						if ($row['Monday'])
							$days_of_week .= 'M,';
						if ($row['Tuesday'])
							$days_of_week .= 'Tu,';
						if ($row['Wednesday'])
							$days_of_week .= 'W,';
						if ($row['Thursday'])
							$days_of_week .= 'Th,';
						if ($row['Friday'])
							$days_of_week .= 'F,';
						if ($row['Saturday'])
							$days_of_week .= 'Sa,';
						if ($row['Sunday'])
							$days_of_week .= 'Su,';
						$days_of_week = substr_replace($days_of_week, '', -1, 1);
						echo $days_of_week;
					}
				?></td>
                <td><?php
					if (!empty($row['timeslot_id']))
					{
						echo date('g:i', strtotime($row['start_time'])); 
						if (date('a', strtotime($row['start_time'])) != date('a', strtotime($row['end_time'])))
						{
							echo date('a', strtotime($row['start_time']));
						}
						echo ' - '.date('g:ia', strtotime($row['end_time']));
					}
				?></td>
                <td><?php
					if (!empty($row['classroom_id']))
					{
						echo $row['b_abbrev'].' '.$row['room_num']; 
					}
				?></td>
                <td><?php echo $row['description']; ?></td>
				
			</tr>
		<?php
		}
			
		?>
    </table>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>